var express = require('express');
var router = express.Router();
var sqlModel = require('../lib/sql');
var utils = require('../utils/index')
// 查询学生列表
router.post('/login', async(req, res, next) => {
    await sqlModel.login(req.body)
        .then(result => {
            // user = result[0];
            if(result.length) {
                let token = utils.generateToken(result);
                res.send({
                    code: 200,
                    token,
                })
            } else {
                res.send({
                    code: 0, msg: '用户名或密码不正确'
                });
            }
        }).catch((err)=>{
            res.send(err);
        })   
})

router.post('/checkToken', async(req, res, next) => {
    let isValid = utils.decodeToken(req.headers['access-token']);
})
 
 

module.exports = router;
